<?php
    include "../database.php";
    
    $data = array('success' => '0');
    $task_id = $_POST["task_id"];
    $method   = $_GET["method"];
    
    if ($method == "accept"){
        $dev_id = $_POST["developer"];
        $query = "UPDATE task SET assigned_id = '$dev_id', task_status = '1' WHERE task_id = '$task_id'";
        $res = executeQuery($query);
        
        //$queryDelete = "DELETE FROM task WHERE story_id = '$story_id'";
        //$res = executeQuery($queryDelete);  

        $data = array('success' => '1');
    }
    
    if ($method == "release"){
        $query = "UPDATE task SET assigned_id = '0', task_status = '0' WHERE task_id = '$task_id'";
        $res = executeQuery($query);
        
        //$queryDelete = "DELETE FROM task WHERE story_id = '$story_id'";
        //$res = executeQuery($queryDelete);       

        $data = array('success' => '1');
    }
    
    if ($method == "create"){
        $story_id = $_POST["story_id"];
        $task_name  = $_POST["task_name"];
        
        $query = "INSERT INTO `TPO15_2013`.`task` (`story_id`, `task_title`) VALUES ('$story_id', '$task_name')";
        //$query = "UPDATE task SET assigned_id = '0', task_status = '0' WHERE task_id = '$task_id'";
        $res = executeQuery($query);
        
        //$queryDelete = "DELETE FROM task WHERE story_id = '$story_id'";
        //$res = executeQuery($queryDelete);       

        $data = array('success' => '1');
    }

    echo json_encode($data);
?>
